﻿using LeHouse.Server.Dto;
using LeHouse.Server.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace LeHouse.Server.WebApi.Controllers
{
    public class IndoorController : ApiController
    {
        Collateral_IndoorService bll = new Collateral_IndoorService();
        /// <summary>
        /// 户内部分的数据添加
        /// </summary>
        /// <param name="s">ajax传过来的需要添加的数据</param>
        /// <returns></returns>       
        [HttpPost]
        [Route("api/Indoor/Postinsert")]
        public bool Insert([FromBody] Collateral_SitePicture parms)
        {
            if(count(parms.T_ReportNumber)>0)
            {
                Collateral_SitePicture parms1 = new Collateral_SitePicture();
                //parms1.Iid = Convert.ToInt64(DateTime.Now.Year.ToString() + DateTime.Now.Month + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond);
                //parms1.P_ReportNumber = parms.P_ReportNumber;
                //parms1.I_purposeID = parms.I_purposeID;
                //parms1.I_floor = parms.I_floor;
                //parms1.I_storey = parms.I_storey;
                //parms1.I_orientationID = parms.I_orientationID;
                //parms1.I_residenceID = parms.I_residenceID;
                //parms1.I_severalKITCHEN = parms.I_severalKITCHEN;
                //parms1.I_severalbathroom = parms.I_severalbathroom;
                //parms1.I_severalBedroom = parms.I_severalBedroom;
                //parms1.I_severaldrawing = parms.I_severaldrawing;
                //parms1.I_drawingID = parms.I_drawingID;
                //parms1.I_roomdescribe = parms.I_roomdescribe;
                //parms1.I_habitableID = parms.I_habitableID;
                //parms1.I_habitable = parms.I_habitable;
                //parms1.I_toiletID = parms.I_toiletID;
                //parms1.I_toilet = parms.I_toilet;
                //parms1.I_kitchenID = parms.I_kitchenID;
                //parms1.I_kitchen = parms.I_kitchen;
                //parms1.I_explain = parms.I_explain;
                //parms1.I_state = 1;
                //parms1.I_Buildingafew = parms.I_Buildingafew;
                //var s=  Request["parms"];
                Collateral_SitePictureService update = new Collateral_SitePictureService();
                if (update.Update(parms1, t => t.T_ReportNumber == parms.T_ReportNumber))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                Collateral_SitePicture parms1 = new Collateral_SitePicture();
                //parms1.Iid = Convert.ToInt64(DateTime.Now.Year.ToString() + DateTime.Now.Month + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond);
                //parms1.P_ReportNumber = parms.P_ReportNumber;
                //parms1.I_purposeID = parms.I_purposeID;
                //parms1.I_floor = parms.I_floor;
                //parms1.I_storey = parms.I_storey;
                //parms1.I_orientationID = parms.I_orientationID;
                //parms1.I_residenceID = parms.I_residenceID;
                //parms1.I_severalKITCHEN = parms.I_severalKITCHEN;
                //parms1.I_severalbathroom = parms.I_severalbathroom;
                //parms1.I_severalBedroom = parms.I_severalBedroom;
                //parms1.I_severaldrawing = parms.I_severaldrawing;
                //parms1.I_drawingID = parms.I_drawingID;
                //parms1.I_roomdescribe = parms.I_roomdescribe;
                //parms1.I_habitableID = parms.I_habitableID;
                //parms1.I_habitable = parms.I_habitable;
                //parms1.I_toiletID = parms.I_toiletID;
                //parms1.I_toilet = parms.I_toilet;
                //parms1.I_kitchenID = parms.I_kitchenID;
                //parms1.I_kitchen = parms.I_kitchen;
                //parms1.I_explain = parms.I_explain;
                //parms1.I_state = 1;
                //parms1.I_Buildingafew = parms.I_Buildingafew;
                //var s=  Request["parms"];
                Collateral_SitePictureService insert = new Collateral_SitePictureService();
                if (insert.Insert(parms1) == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        /// <summary>
        /// 根据报告号获取户内部分的数据
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/Indoor/SelectByid")]
        public Collateral_SitePicture showindoor([FromUri]string P_ReportNumber)
        {
            if(count(P_ReportNumber)>0)
            {
                Collateral_SitePictureService showind = new Collateral_SitePictureService();
                return null; //showind.Community(P_ReportNumber);
            }
            else
            {
                return null;
            }
           
        }
        /// <summary>
        /// 根据报告号去查询户内是否有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int count(string P_ReportNumber)
        {
            return bll.count(P_ReportNumber);
        }
    }
}
